<?php
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2019/11/9
 * Time: 11:14 AM
 */

namespace App\BO\OrderStatus;

use App\Entities\OrderEntity;
use App\Entities\OrderModel as Order;

class OrderStateModifyStore
{
    /**
     * @var OrderEntity
     */
    private $order;

    public function __construct(OrderEntity $order)
    {
        $this->order = $order;
    }

    /**
     * 将订单设置为待支付
     */
    public function toWaitingPay()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_WAITING_PAY);
        $this->order->save();
    }

    /**
     * 将订单设置为待支付，但可源单状态
     */
    public function toWaitingPayCouldDispatch()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_WAITING_PAY_COULD_DISPATCH);
        $this->order->save();
    }

    /**
     * 将订单状态设置为待分配
     */
    public function toDistributing()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_WAITING_DISTRIBUTION);
        $this->order->setShipStatus(Order::SHIP_STATUS_DISTRIBUTION);
        $this->order->save();
    }

    /**
     * 将状态设置为待上门状态
     */
    public function toWaitingService()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_WAITING_SERVICE);

        $this->order->setShipStatus(Order::SHIP_STATUS_PENDING);
        $this->order->save();
    }

    /**
     * 将状态设置为待评价状态
     */
    public function toWaitingComment()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_WAITING_COMMENT);

        $this->order->setShipStatus(Order::SHIP_STATUS_DELIVERED);
        $this->order->save();
    }

    /**
     * 订单服务中
     */
    public function toServicing()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_SERVICING);
        $this->order->save();
    }

    /**
     * 订单报备中
     */
    public function toReported()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_REPORTED);
        $this->order->save();
    }

    /**
     * 设置为退款审核中
     */
    public function toRefundWaitingCheck()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_REFUND_WAITING_CHECK);
        $this->order->save();
    }

    /**
     * 设置为等待第三方平台通知
     */
    public function toRefundWaitingThirdPartNotify()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_REFUND_WAITING_THIRD_PART_NOTIFY);
        $this->order->save();
    }

    /**
     * 设置为后台拒绝退款
     */
    public function toRefundAdminReject()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_REFUND_REJECT_BY_ADMIN);
        $this->order->save();
    }

    /**
     * 设置为用户取消退款申请
     */
    public function toRefundCancelledByUser()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_REFUND_CANCELLED_BY_USER);
        $this->order->save();
    }

    /**
     * 审核通过，状态设置为退款中
     */
    public function toRefunding()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_REFUNDING);
        $this->order->save();
    }

    /**
     * 设置为退款成功
     */
    public function toRefundSuccess()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_REFUND_SUCCESS);

        $this->order->setRefundStatus(Order::REFUND_STATUS_SUCCESS);
        $this->order->save();
    }

    /**
     * 设置为退款成功
     */
    public function toRefundFailed()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_REFUND_FAILED);

        $this->order->setRefundStatus(Order::REFUND_STATUS_FAILED);
        $this->order->save();
    }

    /**
     * 设置为已经评价
     */
    public function toCommented()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_REVIEWED);

        $this->order->setReviewed(1);
        $this->order->save();
    }

    /**
     * 用户取消
     */
    public function toUserCanceled()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_USER_CANCEL);

        $this->order->setClosed(Order::ORDER_CLOSED);
        $this->order->save();
    }

    /**
     * 设置为过期
     */
    public function toExpired()
    {
        $this->order->setOrderState(OrderStateDefinition::STATE_EXPIRED);

        $this->order->setClosed(Order::ORDER_CLOSED);
        $this->order->save();
    }

    /**
     * 将订单关闭
     */
    public function toClosed()
    {
        $this->order->setClosed(Order::ORDER_CLOSED);
        $this->order->save();
    }
}
